package logic

import (
	"context"
	"fmt"
	"person/models/mysql"

	"person/personrpc/internal/svc"
	"person/personrpc/personrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type PerfectLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewPerfectLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PerfectLogic {
	return &PerfectLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *PerfectLogic) Perfect(in *personrpc.PerfectRequest) (*personrpc.PerfectResponse, error) {
	// todo: add your logic here and delete this line
	var findUser mysql.User
	mysql.DB.Debug().Where("id = ?", in.UserId).Find(&findUser)
	if findUser.ID == 0 {
		return nil, fmt.Errorf("当前用户不存在，请重新确认")
	}
	user := mysql.User{

		Image:    in.Image,
		Age:      int(in.Age),
		Sex:      in.Sex,
		Address:  in.Address,
		NickName: in.NickName,
		RealName: in.RealName,
	}
	mysql.DB.Debug().Where("id = ?", in.UserId).Updates(&user)
	return &personrpc.PerfectResponse{
		Id: int64(findUser.ID),
	}, nil
}
